<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户信息</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <!-- 头部搜索 -->
      <el-row :gutter="10">
        <el-col :span="5">
          <div class="grid-content bg-purple">
            <el-form label-width="100px">
              <el-form-item label="邮箱：">
                <el-input
                  v-model="queryinfo.userEmail"
                  clearable
                  placeholder="请输入邮箱"
                  @clear="getmsgList"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </el-col>
        <el-col :span="5">
          <div class="grid-content bg-purple">
            <el-form label-width="80px">
              <el-form-item label="手机号：">
                <el-input
                  v-model="queryinfo.userTel"
                  clearable
                  placeholder="请输入手机号"
                  @clear="getmsgList"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </el-col>
        <!-- <el-col :span="5">
          <div class="grid-content bg-purple">
            <el-form label-width="100px">
              <el-form-item label="交易所账号：">
                <el-input
                  v-model="queryinfo.jysUser"
                  clearable
                  placeholder="请输入交易所账号"
                  @clear="getmsgList"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </el-col> -->
        <el-button type="primary" icon="el-icon-search" @click="getmsgList"
          >搜索</el-button
        >
      </el-row>
      <!-- <el-row>
        <el-col class="restyle" :span="4">总注册人数:{{countALL}}</el-col>
        <el-col class="restyle" :span="4">当前注册人数:{{countByToDay}}</el-col>
        <el-col class="restyle" :span="4">有效用户人数:{{countByIsValid}}</el-col>
      </el-row> -->
      <!-- 审核数据列表 -->
      <template>
        <el-table :data="tableData" stripe border style="width: 100%">
          <el-table-column type="index" label="#"> </el-table-column>
          <el-table-column prop="id" label="ID" width="80"> </el-table-column>
          <el-table-column prop="userTel" label="手机号码"> </el-table-column>
          <el-table-column prop="userEmail" label="邮箱"> </el-table-column>
          <el-table-column prop="levelName" label="等级">
          </el-table-column>
          <el-table-column prop="slHoldToken" label="业绩（T）"> </el-table-column>
           <el-table-column prop="servicechargeName" label="费率"> </el-table-column>
          <el-table-column label="账户状态">
            <template slot-scope="scope">
              <span v-if="scope.row.isFreeze === true">冻结</span>
              <span v-else>正常</span>
            </template>
          </el-table-column>
          <el-table-column prop="isSm" label="实名状态">
            <template slot-scope="scope">
              <span v-if="scope.row.isSm === true">已实名</span>
              <span v-else>未实名</span>
            </template>
          </el-table-column>
          <el-table-column prop="isTb" label="提币状态">
            <template slot-scope="scope">
              <span v-if="scope.row.isTb === true">冻结</span>
              <span v-else>正常</span>
            </template>
          </el-table-column>
          <el-table-column prop="isTb" label="运营中心">
            <template slot-scope="scope">
              <span v-if="scope.row.isXyzx === true">是</span>
              <span v-else>否</span>
            </template>
          </el-table-column>
          <el-table-column prop="" label="操作">
            <template slot-scope="scope">
              <div style="margin-bottom: 5px;">
                <el-button
                  :type="scope.row.isTb === false ? 'primary' : 'success'"
                  size="mini"
                  ref="Tb"
                  @click="Tbsubmit(scope.row.id, scope.row.isTb)"
                >
                  {{ scope.row.isTb === false ? "提币冻结" : "提币解冻" }}
                </el-button>
              </div>
              <div style="margin-bottom: 5px;">
                <el-button 
                  :type="scope.row.isFreeze === true ? 'success' : 'primary'"
                  size="mini"
                  ref="Freeze"
                  @click="Freezesubmit(scope.row.id, scope.row.isFreeze)"
                >
                  {{ scope.row.isFreeze === false ? "账户冻结" : "账户解冻" }}
                </el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="isTb" label="查看资产">
            <template slot-scope="scope">
              <el-button type="danger" size="mini" ref="Freeze" icon="el-icon-view" @click="lookzc(scope.row.id)">
                查看
              </el-button>
            </template>
          </el-table-column>
          <el-table-column  label="修改等级">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" ref="Freeze" icon="el-icon-edit"  @click="changeDj(scope.row.id,scope.row.levelName,scope.row.isLockSj);">
                修改
              </el-button>
            </template>
          </el-table-column>
          <el-table-column  label="修改费率">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" ref="Freeze" icon="el-icon-edit"  @click="getFwfList(scope.row.id,scope.row.servicechargeName);">
                修改
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30]"
        :page-size="queryinfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <el-dialog :title="titleText" :visible.sync="dialogVisible" width="50%">
      <el-table :data="zcTableData" stripe border style="width: 100%">
          <el-table-column prop="userId" label="ID" width="80"> </el-table-column>
          <el-table-column prop="tokenName" label="币种名称"> </el-table-column>
          <el-table-column prop="ldToken" label="流动数量"> </el-table-column>
          <el-table-column prop="djToken" label="冻结数量"> </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog title="等级修改" :visible.sync="changeVisible" width="50%" :before-close="closelevel">
      <el-row :gutter="20">
        <el-col :span="3">当前等级</el-col>
        <el-col :span="6"> <el-input v-model="dateLevel" disabled placeholder="请输入内容"></el-input></el-col>
      </el-row>
       <el-row :gutter="20">
        <el-col :span="3">修改等级</el-col>
        <el-col :span="6"> 
          <el-select v-model="querylevelFrom.levelId" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.levelName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="3">是否锁定</el-col>
        <el-col :span="6"> 
          <el-switch
            v-model="querylevelFrom.isLock"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-text="锁定"
            inactive-text="解锁">
          </el-switch>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="isTrue">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="titleText" :visible.sync="dialogVisible" width="50%">
      <el-table :data="zcTableData" stripe border style="width: 100%">
          <el-table-column prop="userId" label="ID" width="80"> </el-table-column>
          <el-table-column prop="tokenName" label="币种名称"> </el-table-column>
          <el-table-column prop="ldToken" label="流动数量"> </el-table-column>
          <el-table-column prop="djToken" label="冻结数量"> </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 修改费率 -->
    <el-dialog title="修改费率" :visible.sync="flchangeVisible" width="50%" :before-close="closelevel">
      <el-row :gutter="20">
        <el-col :span="3">修改费率</el-col>
        <el-col :span="6"> 
          <el-select v-model="flquerylevelFrom.numvalue" placeholder="请选择">
            <el-option
              v-for="item in floptions"
              :key="item.id"
              :label="item.percentage"
              :value="item.numvalue">
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="flisTrue">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      queryinfo: {
        userTel: "",
        userEmail: "",
        // jysUser: "",
        pageIndex: 1,
        pageSize: 10,
      },
      total: 0,
      countALL: "",
      countByIsValid: "",
      countByToDay: "",
      tableData: [],
      zcTableData:[],
      dialogVisible: false,
      changeVisible:false,
      flchangeVisible:false,
      titleText: "",
      changeValue: "",
      userId: "",
      dateLevel:"",
      querylevelFrom:{
        levelId:"",
        userId:"",
        // numvalue:"",
        isLock:false,
      },
      flquerylevelFrom:{
        userID:"",
        numvalue:"",
        servicechargeName:"",
      },
      options: [],
      floptions:[],
    };
  },
  created() {
    this.getmsgList();
  },
  methods: {
    // 关闭修改弹框
    closelevel(){
      this.querylevelFrom.levelId = ""
      this.changeVisible=false
    },
    // 确认修改 
    async isTrue() {
      const { data: res } = await this.$http.post(
        "currencyAudit/updateLevel",
        this.httputil(this.querylevelFrom)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.changeVisible=false
      this.$message.success(res.msg);
      this.getmsgList();
    },
    // 确认修改费率
    async flisTrue() {
      if(this.flquerylevelFrom.numvalue == 0.20){
        this.flquerylevelFrom.servicechargeName="20%"
      }else if(this.flquerylevelFrom.numvalue == 0.19){
        this.flquerylevelFrom.servicechargeName="19%"
      }else if(this.flquerylevelFrom.numvalue == 0.18){
        this.flquerylevelFrom.servicechargeName="18%"
      }else if(this.flquerylevelFrom.numvalue == 0.17){
        this.flquerylevelFrom.servicechargeName="17%"
      }else{
         this.flquerylevelFrom.servicechargeName="16%"
      }
      const { data: res } = await this.$http.post(
        "currencyAudit/updateUserFwf",
        this.httputil(this.flquerylevelFrom)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.flchangeVisible=false
      this.$message.success(res.msg);
      this.getmsgList();
    },
    // 获取等级
   async changeDj(id,levelName,isLockSj) {
      this.changeVisible=true
      this.querylevelFrom.userId = id
      this.dateLevel = levelName
      this.querylevelFrom.isLock=isLockSj
      this.getFwfList()
      const { data: res } = await this.$http.post(
        "currencyAudit/getLevelList",
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.options=res.data
    },
    // 获取等级
    async getFwfList(id,servicechargeName){
      this.flquerylevelFrom.userID = id
      this.flquerylevelFrom.servicechargeName=servicechargeName
      this.flchangeVisible=true
      const { data: res } = await this.$http.post(
        "currencyAudit/getFwfList",
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.floptions=res.data
      // console.log(res.data)
    },
    // 查看资产
    async lookzc(id) {
      const ids ={userId:id}
      this.dialogVisible=true
      const { data: res } = await this.$http.post(
        "currencyAudit/getUserAssets",
        this.httputil(ids)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.zcTableData=res.data
    },
    // 获取审核列表
    async getmsgList() {
      const { data: res } = await this.$http.post(
        "currencyAudit/getGxEquity",
        this.httputil(this.queryinfo)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.tableData = res.data.UserInfos;
      this.total = res.data.count;
      this.countALL = res.data.countALL;
      this.countByIsValid = res.data.countByIsValid;
      this.countByToDay = res.data.countByToDay;
    },
    // 是否冻结提币
    async Tbsubmit(id, b) {
      if (b == false) {
        b = 1;
      } else {
        b = 0;
      }
      const data = {
        id: id,
        isTb: b,
      };
      const { data: res } = await this.$http.post(
        "currencyAudit/updateUserStatus",
        this.httputil(data)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.getmsgList();
    },
    // 是否冻结账户  { id: a, isFreeze: b },
    async Freezesubmit(id, b) {
      if (b == false) {
        b = 1;
      } else {
        b = 0;
      }
      const data = {
        id: id,
        isFreeze: b,
      };
      const { data: res } = await this.$http.post(
        "currencyAudit/updateUserStatus",
        this.httputil(data)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.getmsgList();
    },
    // 页面数量发生改变
    handleSizeChange(newSize) {
      this.queryinfo.pageSize = newSize;
      this.getmsgList();
    },
    // 页数发生改变
    handleCurrentChange(newCurrent) {
      this.queryinfo.pageIndex = newCurrent;
      this.getmsgList();
    },
  },
};
</script>
<style lang="less" scoped>
.restyle {
  color: #409eff;
  font-size: 18px;
  font-weight: 600;
}
</style>
